package com.test.exam.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.test.exam.domain.Subject;
import com.test.exam.service.SubjectService;

@Controller
public class SubjectController {
	@Autowired
	private SubjectService subjectService;
	
	//현재페이지 과목  리스트
	@RequestMapping(value="/admin/subject/getSubjectsByCurrentPage/{currentPage}", 
					method=RequestMethod.GET)
	public String getSubjectsByCurrentPage(
			@PathVariable int currentPage,
			Model model){
		model.addAttribute("subjectList", subjectService.getAllSubjectsByCurrentPage(currentPage));
		
		model.addAttribute("currentPage", currentPage);
		model.addAttribute("endPage", subjectService.getEndPage());
		
		return "/admin/subject/subjectList";
	}
	
	//과목 입력
	@RequestMapping(value="/admin/subject/addSubject", 
					method=RequestMethod.POST)
	public String addSubject(Subject subject){
		subjectService.addSubject(subject);
		return "redirect:/admin/subject/getSubjectsByCurrentPage/1";
	}
	
	
	//과목 입력폼
	@RequestMapping(value="/admin/subject/addSubjectForm", 
					method=RequestMethod.GET)
	public String addSubjectForm(){
		return "/admin/subject/addSubjectForm";
	}
}





